<?php if(!defined('MS_XTIGER')) exit('Access Denied');
/**
 * Created by openXtiger.org.
 * User: xtiger
 * Date: 2009-5-16
 * Time: 9:59:30
 */

function xtf_template($location) {
    global $_XH_D,$_XC,$_XM;
    $template = empty($_XH_D['template']) ? $_XC['template'] : $_XH_D['template'];
    $language = empty($_XH_D['language']) ? $_XC['language'] : $_XH_D['language'];
    $ext = empty($_XC['view_ext']) ? '.html.php' : $_XC['view_ext'];
    $filename = MS_APPPATH.'./views/'.$template.'/'.$location.$ext;
    if(!file_exists($filename)) return;
    //$location = str_replace(array('/','//'),'_',$location);//add by lunzi on 2009.6.18
    $objfile = MS_CACHEPATH."./tpl/{$language}/{$template}/{$location}.php";
    $tplrefresh = 1;
	if(file_exists($objfile)) {
		if(empty($_XC['tplrefresh'])) {
			$tplrefresh = 0;
		} else {
			if(@filemtime($filename) <= @filemtime($objfile)) {
				$tplrefresh = 0;
			}
		}
	}
	if(1/*$tplrefresh*/) {
	    /*if(!is_dir(MS_CACHEPATH.'./tpl/')){
            @mkdir(MS_CACHEPATH.'./tpl/',0777);
        }*/
        include_once(MS_XTIGER.'./views/XMarkerParser.php');
		_xtf_parse_template($filename, $objfile, "language/$language/",MS_APPPATH.'./views/'.$template.'/');
	}
    return $objfile;
}

function xtiger_xmarker_result($r) {
    global $_XH_D,$_XM,$_UD;
    $objfile = xtf_template($r['location']);
    extract($_XH_D);
    if(is_array($_UD)) {
        extract($_UD);
    }
    include $objfile;
}